import gameEventCtrl from "../common/gameEventCtrl";
import gameModel from "./gameModel";
import gameView from "./gameView";

export default class gameCtrl{
    private gameViewScr:gameView = null
    private gameModelScr:gameModel = null
    private gameEventCtrlScr:gameEventCtrl = null

    public init(gameViewScr:gameView){
        this.gameViewScr = gameViewScr
        this.gameModelScr = new gameModel()
        this.gameViewScr.bindModel(this.gameModelScr)
        this.gameEventCtrlScr =  gameEventCtrl.instance()
        this.gameEventCtrlScr.regesterModel(this,this.gameModelScr,this.gameViewScr)
        this.gameEventCtrlScr.onEventListen()
        this.gameModelScr.init()
    }

    public play(){
        this.gameModelScr.play()
    }

    public exit(){
       this.gameEventCtrlScr.offEventListen()
    }

    public restart(){
        this.gameViewScr.restart()
        this.gameModelScr.restart()
        this.gameModelScr.init()
        this.play()
        }
}